const Koa = require('koa');

const Router = require('koa-router');

const app = new Koa();

const home = new Router();

home.get('/', (ctx, next) => {
  ctx.body = '/home';
}).get('/cs', (ctx, next) => {
  ctx.body = '/home/cs';
})

const page = new Router();

page.get('/', (ctx, next) => {
  ctx.body = '/page';
}).get('/cs', (ctx, next) => {
  ctx.body = '/page/cs';
})

// 使用router实例，装载所有的子路由
const router = new Router();
router.use('/home', home.routes(), home.allowedMethods());
router.use('/page', page.routes(), page.allowedMethods());

// 加载router路由中间件
app.use(router.routes(), router.allowedMethods()).listen(3030, () => {
  console.log('router2');
})